A spinlock is a lock which causes a thread trying to acquire it to wait simply in a loop (“spin”) while repeatedly checking if the lock is available. Since the thread remains active but is not performing a useful task, the use of such a lock is a kind of busy waiting. Once acquired, spinlocks will usually be held until they are explicitly released, although in some implementations they may be automatically released if the thread being waited on (that which holds the lock) blocks, or “goes to sleep.” Because they avoid overhead from operating system process rescheduling or context switching, spinlocks are efficient if threads are likely to be blocked for only short periods. For this reason, operating-system kernels often use spinlocks. By design, no formal technique exists to lock recursively a spinlock. Conventionally, if an attempt was made to lock a spinlock that was already held by a task, pthread or Interrupt Service Routine (ISR), then a livelock situation was encountered, and the spinlock would never be claimed. Conventional coding techniques understand this limitation and software engineers carefully engineer code to avoid such situations.
Specifically, spinlocks were introduced for mutual exclusion on Symmetric Multiprocessor (SMP) architectures and runtime environments. It would be advantageous to support a recursive spinlock, especially in the context of providing SMP support for existing software which supports recursive ISR calls to remove the need to rewrite the existing software.